
package cn.gov.service.impl;

import cn.geracomium.util.service.abs.AbstractService;
import cn.gov.dao.IBedDAO;
import cn.gov.dao.IProvinceAndCityDAO;
import cn.gov.service.IBedService;
import cn.gov.service.ICityAndProvinceService;
import cn.gov.vo.*;
import com.alibaba.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BedServiecImpl extends AbstractService implements IBedService {

    @Resource
    private IBedDAO dao;
    @Override
    public List<Building> getAllBuilding(){

        return this.dao.findAllBuilding() ;
    }
    @Override
    public Map<String,Object> getFloorByBuilding(int id){
        HashMap<String,Object> map = new HashMap<>();
        String resultCode = null ;
        map.put("data",this.dao.findFloorByBuilding(id));
        if(this.dao.findFloorByBuilding(id) != null){
            resultCode = "SUCC";
        }
        map.put("resultCode",resultCode);
        return map ;
    }


    @Override
    public Map<String,Object> getRoomByFloor(int id){
        HashMap<String,Object> map = new HashMap<>();
        String resultCode = null ;
        map.put("data",this.dao.findRoomByFloor(id));
        if(this.dao.findRoomByFloor(id) != null){
            resultCode = "SUCC";
        }
        map.put("resultCode",resultCode);
        return map ;
    }



    @Override
    public Map<String,Object> getBedByRoom(int id){
        HashMap<String,Object> map = new HashMap<>();
        String resultCode = null ;
        map.put("data",this.dao.findBedByRoom(id));
        if(this.dao.findRoomByFloor(id) != null){
            resultCode = "SUCC";
        }
        map.put("resultCode",resultCode);
        return map ;
    }
    @Override
    public void addBuildings(List<Building> buildings){
        this.dao.insertByBatchBuilding(buildings);
    }

    @Override
    public Map<String,Object> addBuilding(Building vo ){
        HashMap<String,Object> map = new HashMap<>();
        this.dao.doCreate(vo);
        map.put("resultCode","SUCC");
        return map ;
    }
    @Override
    public Map<String,Object> addFloor(Floor vo ){
        HashMap<String,Object> map = new HashMap<>();
        this.dao.doCreateFloor(vo);
        map.put("resultCode","SUCC");
        return map ;
    }
    @Override
    public Map<String,Object> addRoom(Room vo ){
        HashMap<String,Object> map = new HashMap<>();
        this.dao.doCreateRoom(vo);
        map.put("resultCode","SUCC");
        return map ;
    }
    @Override
    public Map<String,Object> addBed(Bed vo ){
        HashMap<String,Object> map = new HashMap<>();

       boolean data =  this.dao.doCreateBed(vo);
        map.put("resultCode","SUCC");
        map.put("data",data);
        return map ;
    }
    @Override
    public int getBuildIdByName(String name){
        return this.dao.getBuildIdByName(name);
    }
    @Override
    public int getFloorIdByName(String name){
        return this.dao.getFloorIdByName(name);
    }
    @Override
    public int getRoomIdByName(String name){
        return this.dao.getRoomIdByName(name);
    }

    @Override
    public boolean edit(Building vo ){
       return  this.dao.doUpdate(vo);
    }
    @Override
    public boolean editFloor(Floor vo ){
         return this.dao.doUpdateFloor(vo);
    }
    @Override
    public boolean editRoom(Room vo ){
       return  this.dao.doUpdateRoom(vo);
    }
    @Override
    public boolean editBed(Bed vo ){
        return this.dao.doUpdateBed(vo);
    }
    @Override
    public boolean del(int id){
        return  this.dao.doRemove(id);
    }
    @Override
    public boolean delFloor(int id){
        return  this.dao.doRemoveFloor(id);
    }
    @Override
    public boolean delRoom(int id){
        return  this.dao.doRemoveRoom(id);
    }
    @Override
    public boolean delBed(int id){
        return  this.dao.doRemoveBed(id);
    }
    @Override
    public Map<String,Object> getRoomById(int id){
        HashMap<String,Object> map = new HashMap<>();
        Room room = this.dao.findRoomById(id);
        String resultCode ="";
        if(room != null ){
            map.put("data",room);
            resultCode="SUCC";
        }
        return map;
    }


}

